/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-7-14 下午5:25
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.jdmetro.activities.life;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.dqhl.jdmetro.R;
import com.example.dqhl.jdmetro.base.BaseActivity;
import com.example.dqhl.jdmetro.config.Config;
import com.example.dqhl.jdmetro.utils.Dlog;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * description:便民服务
 * autour:guanluocang
 * date:17/7/14 17:25
 */
public class LifeServiceActivity extends BaseActivity {

    @Bind(R.id.webview_life_service)
    WebView webview_life_service;
    private String service = "";

    @Override
    public void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_life_service);
        initTitleBar(R.string.txt_life_service);
        setRightTextVisibility(View.GONE);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        service = getIntent().getStringExtra("service");
        Dlog.e(service);
        WebSettings webSettings = webview_life_service.getSettings();
        webSettings.setUseWideViewPort(true); //设置webview推荐使用的窗口
        webSettings.setLoadWithOverviewMode(true); //设置webview加载的页面的模式
        webSettings.setUseWideViewPort(true);
        //设置此属性，可任意比例缩放
        webview_life_service.getSettings().setUseWideViewPort(true);
        webview_life_service.getSettings().setLoadWithOverviewMode(true);
// 设置自动加载图片
        webview_life_service.getSettings().setLoadsImagesAutomatically(true);
//支持缩放
        webview_life_service.getSettings().setBuiltInZoomControls(true);
//设置是否支持变焦
        webview_life_service.getSettings().setSupportZoom(true);
// 设置允许访问文件数据
        webview_life_service.getSettings().setAllowFileAccess(true);
//  这是webview保存表单数据
        webview_life_service.getSettings().setSaveFormData(false);
//自适应屏幕 webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
        webview_life_service.getSettings().setLoadWithOverviewMode(true);
// 优先使用缓存
        webview_life_service.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); //  不使用缓存 只从网络获取数据
        webview_life_service.getSettings().setAppCacheEnabled(false);
        if ("1".equals(service)) {
            webview_life_service.loadUrl(Config.life_express);
        } else if ("2".equals(service)) {
            webview_life_service.loadUrl(Config.life_illegal);
        } else if ("3".equals(service)) {
            webview_life_service.loadUrl(Config.life_discount);
        } else {
            webview_life_service.loadUrl(Config.life_calendar);
        }
        webview_life_service.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                showLoadingBar("");
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                hideLoadingBar();
            }
        });


    }

    @Override
    public void initListener() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
}
